package com.ophiux.cs.application.appraise.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.appraise.dto.GetCSDoctorAppraiseDetailsRequest;
import com.ophiux.cs.application.appraise.dto.GetCSDoctorAppraiseDetailsResponse;
import com.ophiux.cs.application.appraise.service.IGetCSDoctorAppraiseDetailsAppService;
import com.ophiux.cs.application.core.ResponsePage;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseDetailObj;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseQueryObj;
import com.ophiux.cs.domain.appraise.repositories.IAppraiseRepository;
import com.ophiux.utils.common.ShiftUtils;
import com.ophiux.utils.exception.OphiuxRepositoryException;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class GetCSDoctorAppraiseDetailsAppService implements IGetCSDoctorAppraiseDetailsAppService {
	@Autowired
	IAppraiseRepository appraiseRepository;
	@Override
	public Result<ResponsePage<GetCSDoctorAppraiseDetailsResponse>> GetCSDoctorAppraiseDetails(GetCSDoctorAppraiseDetailsRequest dto) {
		ResponsePage<GetCSDoctorAppraiseDetailsResponse> respPage = new ResponsePage<GetCSDoctorAppraiseDetailsResponse>();
		
		List<GetCSDoctorAppraiseDetailsResponse> returnList=new ArrayList<GetCSDoctorAppraiseDetailsResponse>();
		//验证参数是否允许为空
		if(!dto.isParamValid()) {
			return Result.fail(ResultEnum.requestParamFail.getCode(), ResultEnum.requestParamFail.getMsg());
		}
		try {
			DoctorAppraiseQueryObj dar=null;
			dar = (DoctorAppraiseQueryObj) ShiftUtils.objToNewObj(dto, DoctorAppraiseQueryObj.class);
			try {
				List<DoctorAppraiseDetailObj> darList=appraiseRepository.getCSDoctorAppraiseDetails(dar);
				returnList = ShiftUtils.objToNewObjList(darList, GetCSDoctorAppraiseDetailsResponse.class);
				
				respPage.setData(returnList);
			} catch (OphiuxRepositoryException e) {
				e.printStackTrace();
				return Result.fail(ResultEnum.requestException.getCode(), e.getExceptionMessage());
			}
		} catch (Exception e) {
			log.info("【GetCSDoctorAppraiseDetails】接口异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return Result.success(respPage, "查询医生咨询评价详情成功");

	}

}
